<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">
    <empty name="address">
        <title>添加地址</title>
        <else/>
        <title>修改地址</title>
    </empty>
    <link href="__PUBLIC__/AmazeUI-2.4.2/assets/css/admin.css" rel="stylesheet" type="text/css">
    <link href="__PUBLIC__/AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css">
    <link href="__PUBLIC__/basic/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="__PUBLIC__/basic/css/LArea.min.css" rel="stylesheet" type="text/css" />
    <link href="__PUBLIC__/basic/css/honeySwitch.css" rel="stylesheet" type="text/css" />
    <link type="text/css" href="__PUBLIC__/css/optstyle.css" rel="stylesheet" />
    <link type="text/css" href="__PUBLIC__/css/style.css" rel="stylesheet" />
    <script src="__PUBLIC__/AmazeUI-2.4.2/assets/js/jquery.min.js" type="text/javascript"></script>
    <script src="__PUBLIC__/AmazeUI-2.4.2/assets/js/amazeui.js"></script>
</head>
<style type="text/css">
body {
    background-color: #EEEEEE;
}

.addressmone {
    width: 100%;
    overflow: hidden;
    background: #fff
}

.addressmone ul {
    width: 100%;
    overflow: hidden;
    margin: auto;
    background-color: #eee;
}

.addressmone ul li {
    width: 100%;
    overflow: hidden;
    background-color: #fff;
        padding: 0 10px;
        margin-bottom: 1px;
}

.addressmone ul li span {
    display: block;
    float: left;
    width: 30%;
    font-size: 16px;
    line-height: 45px;
    color: #666;
}

.addressmone ul li input {
    display: block;
    float: left;
    width: 60%;
    background: none;
    border: 0px;
    font-size: 16px;
    color: #333;
    line-height: 45px;
}
.addressmone ul li textarea {
    display: block;
    float: left;
    width: 100%;
    background: none;
    border: 0px;
    font-size: 16px;
    color: #333;
    padding: 10px 0px;

}

.addressmone ul li select {
    display: block;
    float: left;
    background: none;
    height: 45px;
    border: 0px;
    font-size: 16px;
    color: #333;
    line-height: 45px;
    padding-right: 10px;
    -webkit-appearance: none;
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
    border-radius: 0;
    -webkit-rtl-ordering: logical;
    -webkit-user-select: text;
}
</style>

<body>
    <header data-am-widget="header" class="am-header am-header-default" style="background-color: #F9F9F9">
        <div class="am-header-left am-header-nav">
            <a href="#" onclick="back()" class="">
                <i class="am-header-icon am-icon-angle-left am-icon-sm" style="color: #FFAD01;"></i>
            </a>
        </div>
        <h1 class="am-header-title">
          <a href="#title-link" class="">
              <empty name="address">
                  添加地址
                  <else/>
                  修改地址
              </empty>
          </a>
      </h1>
        <div class="am-header-right am-header-nav">
            <a href="#right-link" onclick="confirmAddress()" class="" style="color: #FFAD01;font-size: 18px;">

               保存
          </a>
        </div>
    </header>

    <form  id="address">

        <input type="hidden" name="address_id" value="{$address.address_id}" >
    <div class="addressmone">
        <ul>
            <li>
                <span>收件人</span>
                <input type="text" name="consignee" value="{$address.consignee}">
            </li>
            <li>
                <span>联系电话</span>
                <input type="phone" name="mobile" value="{$address.mobile}">
            </li>
            <li>
                <span>所在地区</span>
                <input type="text" name="area" id="demo1" readonly="" value="{$address.area}">
                <input type="hidden" name="" id="value1">
            </li>
            <li>
                <textarea name="address" placeholder="请填写详细地址" rows="3">{$address.address}</textarea>
            </li>
            <li style="margin-top: 10px;">
                <span>设为默认</span>
                <span id="is_default"  class="<?php if($address['is_default'] == 1) echo 'switch-on'; else echo 'switch-off'; ?>" onclick="setDefault()" themeColor="gold" id="fly" style="width: 50px;margin-top: 7px;float: right;"> </span>
                <empty name="address">
                    <input name="is_default" type="hidden" value="0" >
                    <else/>
                    <eq name="address.is_default" value="0">
                        <input name="is_default" type="hidden" value="0" >
                        <else/>
                        <input name="is_default" type="hidden" value="1" >
                    </eq>
                </empty>
            </li>
        </ul>
    </div>
    </form>
</body>
<script src="__PUBLIC__/basic/js/LArea.min.js"></script>
<script src="__PUBLIC__/basic/js/LAreaData1.js"></script>
<script src="__PUBLIC__/basic/js/honeySwitch.js"></script>
<script src="__PUBLIC__/js/global.js"></script>
<script src="__PUBLIC__/layer/layer.js"></script>
 <script type="text/javascript">
    var area1 = new LArea();
    area1.init({
        'trigger': '#demo1', //触发选择控件的文本框，同时选择完毕后name属性输出到该位置
        'valueTo': '#value1', //选择完毕后id属性输出到该位置
        'keys': {
            id: 'id',
            name: 'name'
        }, //绑定数据源相关字段 id对应valueTo的value属性输出 name对应trigger的value属性输出
        'type': 1, //数据源类型
        'data': LAreaData //数据源
    });

//    var count= 0;
    function confirmAddress(){

        if($("[name=consignee]").val() == '') {
            modalInfo('联系人不能为空');
            return ;
        }

        if($("[name=mobile]").val() == '') {
            modalInfo('手机号码不能为空');
            return ;
        }
//
//        if($("[name=area]").val() == '') {
//            modalInfo('所在地区不能为空');
//            return ;
//        }

        if($("[name=address]").val() == '') {
            modalInfo('详细地址不能为空');
            return ;
        }

        var formData = new FormData(document.getElementById('address'));
/*        if(count >0)
            return;
        count++;*/
        $.ajax({

            type:"post",
            url:"__URL__/addEditAddress",
            data : formData,
            async:false,
            processData: false,
            contentType: false,
            error:function (data) {
                console.info(data);
                modalInfo("服务器繁忙");
            },
            success:function (data) {
                console.info(data);
                modalInfo(data.msg);
                if(data.status > 0)
                    back();
            }

        });

    }

    function modalInfo(info){
      layer.msg(info);

    }

    function setDefault(){

      var val = $('[name=is_default]').val();
      if(val == 0)
          $('[name=is_default]').val(1);
      else
          $('[name=is_default]').val(0);


      console.info($('[name=is_default]').val());
    }

    var order_id = '{$order_id}';
    function back() {
//        if (/(iPhone|iPad|iPod)/i.test(navigator.userAgent)) {
//            window.location.href = window.document.referrer;
//        } else { window.history.go("-1"); }
        if(!order_id) {
            window.location.href = '__APP__/Home/Me/address'
        }
        else{

            window.location.href = '__APP__/Home/ShopCart/selectAddress?order_id='+order_id;
        }
    }
 </script>

</html>
